void main() {

  // 位置参数
  greet('Hello', 'John');


  // 命名参数
  greet2(hello: 'Hi', name: 'Alice');
  greet2(name: 'Bob');

  // 可选位置参数
  print(say('Bob', 'Howdy'));
  print(say('Bob', 'Howdy', 'smile'));
  print(say('Bob', 'How are you?', 'smoke signal')); // Bob says How are you? with a smoke signal

  // 可选命名参数
  print(say2('Bob', 'Howdy', device: 'smoke signal'));
  print(say2('Bob', 'How are you?', device: 'smile'));

  greet3(name: 'Bob');
  greet3(hello: 'Hi', name: 'Alice');
  greet3();

  // 带默认值的参数
  greet4('Smith'); // Hello Mr/Ms Smith
  greet4('Smith', 'Dr'); // Hello Dr Smith
}

// 位置参数
void greet(String hello, String name) {
  print('$hello, $name!');
}

// 命名参数
void greet2({String hello = 'Hello', String name = 'someone'}) {
  print('$hello, $name!');
}


// 可选位置参数
String say(String from, String msg, [String? device]) {
  var result = '$from says $msg';
  if (device != null) {
    return '$result with a $device';
  }
  return result;
}

// 可选命名参数
String say2(String from, String msg, {String? device}) {
  var result = '$from says $msg';
  if (device != null) {
    return '$result with a $device';
  }
  return result;
}

void greet3({String hello = 'Hello', String? name}) {
  if (name != null) {
    print('$hello, $name!');
  } else {
    print('$hello!');
  }
}

// 带默认值的参数
void greet4(String name, [String prefix = 'Mr/Ms']) {
  print('Hello $prefix $name');
}